<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="text"
        style="display: flex;width: 100%; height: 100px; background-color: limegreen; justify-content: center;align-items: center;">
        点击这里，判断是否绑定事件
    </div>
    <button id="button1" style="display: block;margin: 0 0 8px 0;height: 38px;width: 100%;">添加点击事件</button>
    <button id="button2" style="display: block;margin: 0 0 8px 0;height: 38px;width: 100%;">删除点击事件</button>

    <script src="../../js/jquery.3.5.1.js"></script>
    <script>
        $("#button1").on("click", function () {
            console.log('添加点击事件')
            $("#text").on("dblclick", function () {
                console.log('dblclick')
            })
            $("#text").on("mousedown", function () {
                console.log('mousedown')
            })
            $("#text").on("mouseout", function () {
                console.log('mouseout')
            })
            $("#text").on("mouseup", function () {
                console.log('mouseup')
            })
            $("#text").on("resize", function () {
                console.log('resize')
            })
            // 添加命名空间：myNamespace
            $("#text").on("click.myNamespace", function () {
                console.log('click')
                console.log('所有的事件：', $._data($("#text").get(0), "events"))
                
                var objEvt = $._data($("#text").get(0), "events")["click"];
                console.log('objEvt', objEvt)
                if(objEvt[0].namespace == "myNamespace") console.log('这是有命名空间的，为：', objEvt[0].namespace)
                if (objEvt) {
                    console.log("bind click");
                } else {
                    console.log("Not bind click");
                }
            })
        })
        $("#button2").on("click", function () {
            console.log('删除点击事件')
            $("#text").off("click")
            $("#text").off("dblclick")
            $("#text").off("mousedown")
            $("#text").off("mouseout")
            $("#text").off("resize")
            $("#text").off("mouseup")
        })
    </script>
</body>

</html>